package com.haoshuang.zhouzhoubang.ui.dialog

import android.content.Context
import com.haoshuang.zhouzhoubang.R
import com.haoshuang.zhouzhoubang.databinding.DialogShowOrderPriceBinding
import com.lxj.xpopup.core.BottomPopupView
import com.mufeng.libs.utils.ktx.convertDouble
import com.mufeng.libs.utils.view.clickWithTrigger
import com.mufeng.libs.utils.view.visibleOrGone
import java.math.RoundingMode

class ShowOrderPriceDialog(
    context: Context,
    private val prepayments_amount: String, // 预付款
    private val nightPrice: String, // 夜间服务费
    private val teamPrice: String, // 门店长分成
    private val teamLeaderPrice: String, // 负责人分成
    private val teamMemberPrice: String, // 订单成员分成
    private val totalPrice: String, // 总到手价
    private val minePrice: String, // 我的到手价
) : BottomPopupView(context) {

    override fun getImplLayoutId(): Int {
        return R.layout.dialog_show_order_price
    }

    private lateinit var binding: DialogShowOrderPriceBinding

    override fun onCreate() {
        super.onCreate()
        binding = DialogShowOrderPriceBinding.bind(popupImplView)
        binding.ivClose.clickWithTrigger { dismiss() }
        binding.tvOk.clickWithTrigger { dismiss() }

        val minus = totalPrice.toBigDecimal().minus(nightPrice.toBigDecimal()).setScale(2, RoundingMode.FLOOR).toString()

        binding.llNightPrice.visibleOrGone((nightPrice.toDoubleOrNull()?:0.0) != 0.0)
        binding.llAdvanceCharge.visibleOrGone((prepayments_amount.toDoubleOrNull() ?: 0.0) != 0.0)

        binding.tvOrderPrice.text = "¥${minus}"
        binding.tvNightPrice.text = "¥${nightPrice}"
        binding.tvAdvanceCharge.text = "¥${prepayments_amount}"
        // 门店长分成
        binding.tvTeamPrice.text = "¥${teamPrice}"
        binding.llTeamPrice.visibleOrGone(teamPrice.isNotEmpty() && teamPrice.convertDouble() != 0.0)
        // 门店负责人分成
        binding.tvTeamLeaderPrice.text = "¥${teamLeaderPrice}"
        binding.llTeamLeaderPrice.visibleOrGone(teamLeaderPrice.isNotEmpty() && teamLeaderPrice.convertDouble() != 0.0)
        // 订单成员分成
        binding.tvTeamMemberPrice.text = "¥${teamMemberPrice}"
        binding.llTeamMemberPrice.visibleOrGone(teamMemberPrice.isNotEmpty() && teamMemberPrice.convertDouble() != 0.0)
        // 合计到手价   显示我的到手价
        binding.tvTotalPrice.text = "¥${minePrice}"
    }

}